-- @owner: @kyeleze
-- @date: 2022/5/13
-- @testpoint: 显式调用模式下,自定义函数中argument_type的类型与cast的source_type类型不一致但可以二进制强制转化; 创建成功

--step1:建立自定义类型转换函数;expect:创建函数成功
create or replace function text_to_money
(
    in text
)
returns money
as
$$
declare
count money;
begin
select ($1::integer::money) into count;
return count;
end;
$$
language plpgsql;
/

--step2:创建显式调用模式下转换关系;expect:创建转换关系成功
drop cast if exists (varchar as money) cascade;
create cast (varchar as money) with function text_to_money(text);

--step3:清理环境;expect:成功
drop cast if exists (varchar as money) cascade;
drop function if exists text_to_money(text) cascade;
